<template>
  <div class="page-login df aic jcc">
    <div class="container df fdc aic jcc">
      <h2>系统登陆</h2>
      <el-form :model="formData" :rules="rules" ref="formRef" size="small">
        <!-- 用户名 -->
        <el-form-item prop="account">
          <el-input
            prefix-icon="iconfont icon-user"
            v-model="formData.account"
          ></el-input>
        </el-form-item>

        <!-- 密码 -->
        <el-form-item prop="password">
          <el-input
            v-model="formData.password"
            :type="flag ? 'text' : 'password'"
            @keyup.native.enter="submit"
          >
            <i slot="prefix" class="iconfont icon-clock"></i>
            <i
              slot="suffix"
              class="iconfont"
              :class="flag ? 'icon-openeyes' : 'icon-closeeyes'"
              @click="flag = !flag"
            ></i>
          </el-input>
          <!-- prefix-icon="iconfont icon-clock"   suffix-icon="iconfont icon-closeeyes"-->
        </el-form-item>

        <!-- 登录 -->
        <el-form-item>
          <el-button type="primary" class="btn" @click="submit">登录</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import {mapActions} from 'vuex'
export default {
  data() {
    return {
      //节流loading
      loading:true,
      formData: {
        account: '',
        password: '',
      },
      //眼睛---方法一：三目运算+动态绑定
      flag: false,
      rules: {
        //内置规则
        account: [
          {required: true, message: '请输入用户名', trigger: 'blur'},
          {min: 3, max: 7, message: '长度在 3 到 7 个字符', trigger: 'blur'},
        ],
        password: [
          {required: true, message: '请输入密码', trigger: 'blur'},
          {min: 6, max: 10, message: '长度在6到10个字符', trigger: 'blur'},
        ],
      },
    }
  },
  methods: {
    ...mapActions('user', ['A_login']),
    submit() {
      //获取表单数据
      this.$refs.formRef.validate(async valid => {
        // console.log('valid :>> ', valid);
        //判断
        if (valid) {
          // console.log('"验证成功  发送请求":>> ', this.formData)
          await this.A_login(this.formData)
          this.$router.push('/home')
        } else {
          // console.log('"验证失败":>> ', this.formData)
          console.log('验证失败')
        }
      })
    },
  },
}
</script>

<style lang="scss" scoped>
.page-login {
  width: 100%;
  height: 100%;
  background: url('@/assets/images/bg1.jpg');
  color: #fff;
}

.container {
  width: 300px;
  h2 {
    margin-bottom: 20px;
    text-align: center;
    font-weight: bold;
  }
  .btn {
    width: 300px;
    outline: none;
    color: #fff;
  }
}
:deep(.el-input__inner) {
  background-color: transparent;
  color: #fff;
}
// ::v-deep.el-input__inner{
//   background-color: transparent;
// }
</style>
